package com.chixing.ih.module.programmer.mapper.provider;

import com.chixing.ih.module.programmer.pojo.PersonalProject;
import com.chixing.ih.util.EmptyUtil;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘岩
 * Date: 2020-09-30
 * Time: 8:47
 *
 * @version 1.0
 */
public class PersonalProjectMapperProvider {

    public String insertOne() {
        return new SQL() {{
            INSERT_INTO("tbl_personal_project");
            VALUES("user_id", "#{userId}");
            VALUES("project_title", "#{projectTitle}");
            VALUES("project_desc", "#{projectDesc}");
            VALUES("project_url", "#{projectUrl}");
            VALUES("create_time", "#{createTime}");
        }}.toString();
    }


    public String deleteOneById() {
        return new SQL() {{
            UPDATE("tbl_personal_project");
            SET("is_deleted=1");
            WHERE("id=#{id}");
        }}.toString();
    }


    public String updateOne(PersonalProject personalProject) {
        return new SQL() {{
            UPDATE("tbl_personal_project");
            if (!EmptyUtil.isEmpty(personalProject.getProjectDesc())) {
                SET("project_desc=#{projectDesc}");
            } if (!EmptyUtil.isEmpty(personalProject.getProjectTitle())) {
                SET("project_title=#{projectTitle}");
            }
            if (!EmptyUtil.isEmpty(personalProject.getProjectUrl())) {
                SET("project_url=#{projectUrl}");
            }
            WHERE("id=#{id}");

        }}.toString();


    }

    public String listAll() {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_personal_project");
            WHERE("is_deleted=0 AND user_id=#{userId}");

        }}.toString();
    }

    public String getProjectTitle() {
        return new SQL() {{
            SELECT("project_title");
            FROM("tbl_personal_project");
            WHERE("is_deleted=0 AND user_id=#{userId}");

        }}.toString();
    }


}
